package com.aitoedu.server.controller;

import cn.dev33.satoken.util.SaResult;
import com.aitoedu.server.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@CrossOrigin
public class UploadController {
    @Autowired
    private AliOSSUtils aliOSSUtils;
    @PostMapping("/upload")
    public SaResult upload(MultipartFile file) throws Exception {
        log.info("file:{}", file.getOriginalFilename());
        // 调用阿里云工具类
        String url = aliOSSUtils.upload(file);
        log.info("文件上传成功！" + url);

        return SaResult.code(200).setData(url);
    }
}
